package bookSystem.operations;

import bookSystem.book.Book;
import bookSystem.book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    //归还图书
    public void work(BookList bookList){
        System.out.println("归还图书");
        System.out.print("请输入要归还的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if (name.equals(book.getName())){
                System.out.println(book.toString());
                if (book.isBorrowed() == true){
                    book.setBorrowed(false);
                    System.out.println("还书成功");
                }else{
                    System.out.println("你没有借阅该图书，还书失败");
                }
            }
        }
    }
}
